const ejs = require('ejs')
const fs = require('fs')
const http = require('http')

const proxy = http.createServer((req, res) => {
    fs.readFile('./views/index.ejs', (err, data) => {
        let template = data.toString()

        let dictionary = {
            mode: '开心得很',
            news: [
                {title: '正确', count: 10},
                {title: '哈哈', count: 12},
                {title: '错误', count: 29}
            ]
        }

        let html = ejs.render(template, dictionary)

        res.writeHead(200, {'Content-Type': 'text/html;charset=UTF-8'})
        res.end(html)
    })
})

proxy.listen(80, '127.0.0.1', () => {
    console.log('127.0.0.1:80')
})